package com.gll.controller;

import com.gll.pojo.Pagination;
import com.gll.pojo.Product;
import com.gll.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/productController")
public class ProductController {

    private ProductService productService;

    @RequestMapping("/selProduct")
    public Pagination<Product> selProduct(@RequestParam Map<String,Object> map){

        Pagination<Product> page = new Pagination<Product>(Long.parseLong(map.get("pageNow").toString()),4);
//        System.out.println(pagination);
        page.setConditionMap(map);
        // 查询总条数、计算总页数
        page.setTotalCount(productService.selCount(page));
        // 查询当前页的具体数据
        page.setResultList(productService.selProduct(page));
//        List<Product> products = productService.selProduct(page);
//        page.setResultList(products);
        return page;
    }

    @Autowired
    public void setProductService(ProductService productService) {
        this.productService = productService;
    }
}
